package com.ruoyi.GooverGUI.controller;


import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.Goover.controller.StudyEnglishController;
import com.ruoyi.Goover.domain.SE2;
import com.ruoyi.Goover.domain.StudyEnglish;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.GooverGUI.domain.GooverGUI;
import com.ruoyi.GooverGUI.service.IGooverGUIService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * GooverGUIController
 * 
 * @author luobom
 * @date 2021-12-08
 */
@RestController
@RequestMapping("/GooverGUI/GooverGUI")
public class GooverGUIController extends BaseController
{
    @Autowired
    private IGooverGUIService gooverGUIService;
    @Autowired
    private StudyEnglishController studyEnglishController;

    /**查询标签
     *
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:list')")
    @PostMapping("/querylabel")
    public TableDataInfo queryLabel(@RequestBody List<String> strlabel){
        List<TableDataInfo> result=new ArrayList<>();
        for(String val:strlabel){
            StudyEnglish ste=new StudyEnglish();
            ste.setSearchValue(val);
            result.add(studyEnglishController.list(ste));
        }
        List<SE2> ret=new ArrayList<>();
        for(TableDataInfo t:result){
            ret.addAll((Collection<? extends SE2>) t.getRows());
        }


        //这里去重
        List<SE2> ret2=new ArrayList<>();
        String v="yes";
        for(SE2 smain:ret){
            for(SE2 subordinate:ret2){
                if(smain.getId().equals(subordinate.getId())){
                    v="no";
                }
            }

            if(v.equals("yes")){
                ret2.add(smain);
            }else{
                v="yes";
            }
        }

        return getDataTable(ret2);
    }

    /**查询卡片
     *
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:list')")
    @PostMapping("/queryunit")
    public TableDataInfo queryunit(@RequestBody List<String> Strunit){
        List<TableDataInfo> result=new ArrayList<>();
        for(String val:Strunit){
            StudyEnglish ste=new StudyEnglish();
            ste.setUnit(val);
            result.add(studyEnglishController.list(ste));
        }
        List<StudyEnglish> ret=new ArrayList<>();

        for(TableDataInfo t:result){
            ret.addAll((Collection<? extends StudyEnglish>) t.getRows());
        }

        Collections.reverse(ret);
        return getDataTable(ret);
    }

    /**
     * 查询GooverGUI列表
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:list')")
    @GetMapping("/list")
    public TableDataInfo list(GooverGUI gooverGUI)
    {
        startPage();
        List<GooverGUI> list = gooverGUIService.selectGooverGUIList(gooverGUI);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:list')")
    @GetMapping("/submitover")
    public AjaxResult submitover()
    {
        return gooverGUIService.submitover();
    }



    /**
     * 导出GooverGUI列表
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:export')")
    @Log(title = "GooverGUI", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GooverGUI gooverGUI)
    {
        List<GooverGUI> list = gooverGUIService.selectGooverGUIList(gooverGUI);
        ExcelUtil<GooverGUI> util = new ExcelUtil<GooverGUI>(GooverGUI.class);
        util.exportExcel(response, list, "GooverGUI数据");
    }

    /**
     * 获取GooverGUI详细信息
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(gooverGUIService.selectGooverGUIById(id));
    }

    /**
     * 新增GooverGUI
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:add')")
    @Log(title = "GooverGUI", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GooverGUI gooverGUI)
    {
        return toAjax(gooverGUIService.insertGooverGUI(gooverGUI));
    }

    /**
     * 修改GooverGUI
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:edit')")
    @Log(title = "GooverGUI", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SE2 se)
    {
        StringBuffer uid2=new StringBuffer();
        for(String uid:se.getSearchValue()){
            uid2.append(uid+"|");
        }
        GooverGUI studyEnglish=new GooverGUI(se.getId(),se.getUid(),se.getUnit(),se.getWord(),se.getCx(),se.getSy(),se.getGoover(),uid2.toString());
        studyEnglish.setRemark(se.getRemark());
        studyEnglish.setCourseuid(se.getCourseuid());


        return toAjax(gooverGUIService.updateGooverGUI(studyEnglish));
    }

    /**
     * 删除GooverGUI
     */
    @PreAuthorize("@ss.hasPermi('GooverGUI:GooverGUI:remove')")
    @Log(title = "GooverGUI", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gooverGUIService.deleteGooverGUIByIds(ids));
    }
}
